<template>
  <div class="myContainer">
    <!-- 头部标题 start -->  
    <el-row class="myBorderBottom">
      <el-col :span="7" class="myTitleText myLineHeight_40px">
        {{title}}
      </el-col>
      <el-col :span="17" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="add">新增</el-button>
      </el-col>
    </el-row>
    <!-- 头部标题 end -->
    <el-row :gutter="10" class="myPaddingTop_10px">
      <el-col :span="4">
        <template>
          <el-select v-model="majorSelected"
            clearable
            placeholder="全部考核类型">
            <el-option
              v-for="item in major"
              :key="item.type_name"
              :label="item.type_name"
              :value="item.type_id">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="4">
        <template>
          <el-select v-model="subtypeSelected"
            clearable
            placeholder="全部考核项目">
            <el-option
              v-for="item in subtypeOption"
              :key="item.subtype_id"
              :label="item.subtype_name"
              :value="item.subtype_id">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="6">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" @click="search">查询</el-button>
      </el-col>
    </el-row>
    
    <el-row class="myPaddingTop_10px">
      <el-col :span="24">
        <template>
          <el-table
            border
            :data="list"
            :stripe = true
            v-loading="loading"
            style="width: 100%">
            <el-table-column
              label="序号"
              type="index"
              width="100">
            </el-table-column>
            <el-table-column
              label="考核专业"
              prop="type_name"
              width="120">
            </el-table-column>
            <el-table-column
              label="考核项目"
              prop="subtype_name"
              width="120">
            </el-table-column>
            <el-table-column
              label="标准代码"
              prop="st_no">
            </el-table-column>
            <el-table-column
              label="考核内容"
              prop="st_content">
              <template scope="scope">
                <span class="myTabTitle">{{scope.row.st_content}}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="考核标准"
              prop="st_info">
              <template scope="scope">
                <span class="myTabTitle">{{scope.row.st_info}}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column
              label="不合格扣分值"
              prop="st_value"
              width="120">
            </el-table-column> -->
            <el-table-column
              label="适用小区类型"
              prop="st_range">
            </el-table-column>
            <el-table-column
              label="启用状态"
              prop="status"
              width="100">
              <template scope="scope">
                <span v-if="scope.row.status==1">启用</span>
                <span v-else>禁用</span>
              </template>
            </el-table-column>
            <el-table-column
              label="功能操作"
              width="120">
              <template scope="scope">
                <el-button class="look" type="text" size="small" @click="info(scope.row.st_id)">详情</el-button> |
                <el-button class="look" type="text" size="small" @click="update(scope.row.st_id)">编辑</el-button> |
                <el-button class="look" type="text" size="small" @click="ondelete(scope.row.st_id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-col>
    </el-row>
    
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>

  </div>
</template>     
  
<style scoped>
  .myBorderBottom{
    border-bottom:1px solid #dbdbdb;
    padding-bottom: 5px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleText{
    font-weight: 500;
    font-size: 16px;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
  .myred{
    color: #f00;
    font-size: 12px;
  }
  .myMarginBottom_10px{
    margin-bottom: 10px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
  } 
  .myTabTitle{
    display: -webkit-box;
    /*! autoprefixer: off */
    -webkit-box-orient: vertical;
    /* autoprefixer: on */
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
</style>

<script> 
  import { getTypeList , getStandardList , deleteStandard , getSubtypeList } from "@/api/quality";
  export default {
    data(){
      return{
        title:"考核标准管理",
        page_num:1,
        page_size:10,
        total:null,
        list:[],
        loading:false,
        regionOptions: [],
        regionOptSelected: [],
        majorSelected:"",
        major:[],
        kw:"",
        subtypeSelected:'',
        subtypeOption:[]
      }
    },
    components: {

    },
    created(){
      let vm=this;
      document.title=vm.title; 
      vm.ongetTypeList();
      
      let assessmentStandardConfig=window.sessionStorage.getItem("assessmentStandardConfig");
      if(assessmentStandardConfig){
        let config=JSON.parse(assessmentStandardConfig);
        vm.majorSelected=config.majorSelected;
        vm.kw=config.kw;
        vm.page_num = Number(config.page_num);
        window.sessionStorage.removeItem("assessmentStandardConfig");
      }else{
        vm.page_num = 1;
      }
      vm.ongetStandardList();
    },
    computed: { 

    },
    filters:{ 
      
    },
    watch: {
      majorSelected(val){
        this.subtypeSelected='';
        val ? this.ongetSubtypeList() : this.subtypeOption=[];        
      }
    },
    methods:{
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.ongetStandardList();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.ongetStandardList();
      },
      search(){
        this.ongetStandardList();
      },
      add(){
        this.$router.push({
          path:"assessmentStandardComonents",
          query:{
            type:"add"
          }
        })
      },
      info(st_id){
        let vm=this;
        let assessmentStandardConfig={
          majorSelected:vm.majorSelected,
          kw:vm.kw,
          page_num:vm.page_num
        }
        window.sessionStorage.setItem("assessmentStandardConfig",JSON.stringify(assessmentStandardConfig));
        vm.$router.push({
          path:"assessmentStandardComonents",
          query:{
            type:"info",
            id:st_id
          }
        })
      },
      update(st_id){
        let vm=this;
        let assessmentStandardConfig={
          majorSelected:vm.majorSelected,
          kw:vm.kw,
          page_num:vm.page_num,
        }
        window.sessionStorage.setItem("assessmentStandardConfig",JSON.stringify(assessmentStandardConfig));
        vm.$router.push({
          path:"assessmentStandardComonents",
          query:{
            type:"update",
            id:st_id
          }
        })
      },
      ondelete(st_id){
        let vm=this; 
        vm.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteStandard(st_id).then(response => {
            vm.$message.success("执行成功！");
            vm.ongetStandardList();
          }).catch(error => {
            vm.$message.error("执行失败！"+error.response.data.error_msg);
          })
        }).catch(() => {
          vm.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });  
      },
      ongetStandardList(){
        let vm=this;
        let params={
          type_id:vm.majorSelected,
          subtype_id:vm.subtypeSelected,
          keyword:vm.kw,
          page_num:vm.page_num,
          page_size:vm.page_size
        }
        vm.loading=true;
        getStandardList(params).then(response => {
          let res=response.data;
          vm.list=res.rows;
          vm.page_size=res.page_size;
          vm.page_num=res.page_num;
          vm.total=res.total;
          vm.loading=false;
        }).catch(error => {
          vm.loading=false;
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      },
      ongetTypeList(){//类型列表
        let vm=this;
        let params={ 
          page_num:1,
          page_size:10000
        } 
        getTypeList(params).then(response => {
          let res=response.data;
          vm.major=res.rows; 
        }).catch(error => { 
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      },
      ongetSubtypeList(){
        let vm=this;
        let params={
          keyword:'',
          type_id:vm.majorSelected,
          page_num:1,
          page_size:999
        }
        getSubtypeList(params).then(response => {
          let res=response.data;
          vm.subtypeOption=res.rows;
        }).catch(error => {
          vm.$message.error("执行失败！"+error.response.data.error_msg);
        })
      },

    }
}
</script>

